//app.js
App({
    onLaunch: function () {
        /*var logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs)*/
        var app = this;
        app.globalData.extJson = wx.getExtConfigSync();
        //app.log('extJson', this.globalData.extJson);
        app.http = require('/pages/http/api.js');
        // app.globalData.UploadUrl ="http://192.168.1.84:8008/MiniCommon/UploadImg";
        app.globalData.UploadUrl = "https://wxapp.aimeifa.com/MiniCommon/UploadImg";
    },
    globalData: {
        userInfo: null
    },
    getUserall: function (func) {
        var app = this,
            appID = app.globalData.extJson.Appid;
        if (app.globalData.userInfo) {
            func(app.globalData.userInfo);
            return;
        }

        wx.login({
            success: res => {
                wx.showLoading({
                    title: '登录中..',
                })
                var code = res.code;
                wx.getUserInfo({
                    lang: "zh_CN",
                    success: res => {
                        app.log('getUserInfo', res);
                        app.http.POST("/User/ThirdLogin", {
                            appid: appID,
                            code: code,
                            encryptedData: res.encryptedData,
                            iv: res.iv
                        },
                            (err, data) => {
                                if (data.code == 1) {
                                    app.globalData.userInfo = data.data.userData;
                                    app.http.setCookie(data.data.cookie);
                                    func(app.globalData.userInfo);
                                }
                                wx.hideLoading();
                            })

                        //临时请求用户信息数据 
                        // app.http.POST("/MiniCardUser/GetCardUserInfo",{},(err,data)=>{
                        //   app.globalData.userInfo=data;
                        //   func(app.globalData.userInfo);
                        //   console.log(data);
                        // }) 


                        // wx.request({
                        //   url: app.http+'/User/ThirdLogin',
                        //   method:'POST',
                        //   data: {
                        //     appid: appID,
                        //     code:code,
                        //     encryptedData: res.encryptedData,
                        //     iv:res.iv
                        //   },
                        //   header: {
                        //     'content-type': 'application/json' // 默认值
                        //   },
                        //   success: function (res) {
                        //     console.log(res.data);
                        //   }
                        // })
                    }
                })

            }
        })
    },
    log: function () {
        //console.log.apply(console, arguments);
    },
})